package itheima.d07;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

//掌握LocalDate类
public class Test2 {
    public static void main(String[] args) {
        //获取当前日期
        LocalDate now = LocalDate.now();


        //获取当前日期的信息：年，月，日
        System.out.println("年："+now.getYear());
        System.out.println("月："+now.getMonthValue());
        System.out.println("日："+now.getDayOfMonth());
        System.out.println("周日："+now.getDayOfWeek());
        System.out.println("年日："+now.getDayOfYear());


        //直接修改当前日期：年，月，日
        LocalDate newDate = now.withYear(2020).withMonth(5).withDayOfMonth(10);
        System.out.println("设置后新的日期："+newDate);




        //添加指定的时间：年，月，日，时，分，秒
        System.out.println("一年后："+now.plusYears(1));
        System.out.println("一个月后："+now.plusMonths(1));
        System.out.println("一天后："+now.plusDays(1));

        //比较判断时间的先后：
        LocalDate date1 = LocalDate.of(2002, 1, 1);
        LocalDate date2 = LocalDate.of(2000, 1, 1);
        if (date1.isAfter(date2)){
            System.out.println("date1比date2晚");
            System.out.println("相差：" + ChronoUnit.DAYS.between(date2, date1) + "天");
        }else {
            System.out.println("date1比date2早");
            System.out.println("相差：" + ChronoUnit.DAYS.between(date1, date2) + "天");
        }



    }
}
